package com.example.administrator.printoutindemo.fragment;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RadioButton;

import com.example.administrator.printoutindemo.GPSMainActivity;
import com.example.administrator.printoutindemo.ListByQRCodeActivity;
import com.example.administrator.printoutindemo.LoginActivity;
import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.StoreListInventoryActivity;
import com.example.administrator.printoutindemo.StoreOutStorageCheckList1Activity;
import com.example.administrator.printoutindemo.StoreSubmitProject1Activity;
import com.example.administrator.printoutindemo.StoreSubmitProjectListActivity;
import com.example.administrator.printoutindemo.http.SPUtil;
import com.example.administrator.printoutindemo.services.dyjApplication;


public class BottomFragment extends Fragment {

    private RadioButton frg_btn_index = null;
    private RadioButton frg_btn_me = null;
    private RadioButton frg_btn_list = null;
    String rolesId = "0";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View view = inflater.inflate(R.layout.fragment_bottom, container, false);


        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);

        frg_btn_index = (RadioButton) getActivity().findViewById(R.id.frg_btn_index);
        frg_btn_me = (RadioButton) getActivity().findViewById(R.id.frg_btn_me);
        frg_btn_list = (RadioButton) getActivity().findViewById(R.id.frg_btn_list);
//		rolesId = ((dyjApplication) getActivity().getApplication()).get_roles_id();
        rolesId = SPUtil.getString(getActivity(), "roles_id", "");
        //物料员的rolesId为3,则显示列表按钮,
        if (rolesId.equals("3")) {
            frg_btn_list.setVisibility(View.VISIBLE);
        }
        //仓管员为2，显示库存列表
        if (rolesId.equals("2")) {
            frg_btn_list.setText("库存列表");
            frg_btn_list.setVisibility(View.VISIBLE);
        }

        frg_btn_me.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
//				Intent intent = new Intent();
//				intent.setClass(getActivity(),WebserviceConfigActivity.class);
//				getActivity().startActivity(intent);
            }
        });

        frg_btn_index.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                // 仓管员的rolesId为2,跳转到扫码页面
                if (rolesId.equals("2")) {
                    Intent listIntent1 = new Intent();
                    listIntent1.setClass(getActivity(), ListByQRCodeActivity.class);
                    startActivity(listIntent1);
                }
                // 物料员的rolesId为3,跳转到扫码页面
                if (rolesId.equals("3")) {
                    Intent listIntent1 = new Intent();
                    listIntent1.setClass(getActivity(), StoreSubmitProject1Activity.class);
                    startActivity(listIntent1);
                }
                // 审核人的rolesId为4,跳转到扫码页面
                if (rolesId.equals("4")) {
                    Intent listIntent1 = new Intent();
                    listIntent1.setClass(getActivity(), StoreOutStorageCheckList1Activity.class);
                    startActivity(listIntent1);
                }
                // GPS定位的rolesId为-1,跳转到GPS定位页面
                if (rolesId.equals("-1")) {
                    Intent listIntent1 = new Intent();
                    listIntent1.setClass(getActivity(), GPSMainActivity.class);
                    startActivity(listIntent1);
                }
            }
        });

        frg_btn_list.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 物料员的rolesId为3,跳转到自动出库密码显示页面
                if (rolesId.equals("3")) {
                    Intent listIntent1 = new Intent();
                    listIntent1.setClass(getActivity(), StoreSubmitProjectListActivity.class);
                    startActivity(listIntent1);
                }
                //仓管员为2，跳转到库存页面
                if (rolesId.equals("2")) {

                    Intent listIntent1 = new Intent();
                    listIntent1.setClass(getActivity(), StoreListInventoryActivity.class);
                    startActivity(listIntent1);
                }
            }
        });

    }


}